package org.springblade.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.system.dto.ProjectManageDTO;
import org.springblade.system.entity.ProjectManage;
import org.springblade.system.service.IProjectManageService;
import org.springblade.system.vo.ProjectManageVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @author wzy
 * @date 2022/1/11
 */
@Slf4j
@AllArgsConstructor
@NoArgsConstructor
@RestController
@RequestMapping("system/project_manage")
@Api(value = "项目管理",tags = "项目管理")
public class ProjectManageController extends BladeController {

	@Resource
	IProjectManageService service;
	/**
	 * 分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "分页", notes = "分页")
	public R<IPage<ProjectManageVO>> page(@ApiParam(value = "项目管理") ProjectManageDTO pageDto, Query query) {
		IPage<ProjectManageVO> managePage =
			service.managePage(pageDto, Condition.getPage(query));
		return R.data(managePage);
	}

	/**
	 * 新增
	 */
	@PostMapping("/add")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "新增项目管理", notes = "新增项目管理")
	public R<Object> add(@ApiParam(value = "项目管理") @RequestBody ProjectManage entity) {
		return R.data(service.add(entity));
	}

	/**
	 * 修改
	 */
	@PostMapping("/edit")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "修改", notes = "修改")
	public R<Object> edit(@ApiParam(value = "项目管理") @RequestBody ProjectManage entity)  {
		return R.status(service.edit(entity));
	}
	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "删除", notes = "删除")
	public R<Object> remove(@ApiParam(value = "项目管理表ids")  @RequestParam(value = "ids",required = false) List<Long> ids) {
		return R.status(service.removeByid(ids));
	}

	@PostMapping(value = "/upload")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "图片上传", notes = "传入图片")
	public R fileUpload(@ApiParam(value = "图片", required = true) @RequestParam(value = "file") MultipartFile file,
						@ApiParam(value = "0 项目logo 1 登录页图片 2浏览器图标", required = true) @RequestParam(value = "type") Integer type
	                    )throws IOException{
		return service.upload(type,file);
	}


}
